// 220126

// child_process.exec(command[, options], callback)
// 使用同级目录下的 support.js

const fs = require('fs');
const child_process = require('child_process');

for (var i=0; i<3; i++) {
	// 异常：仅在当前目录下执行时OK
	// var workerProcess = child_process.exec('node support.js ' + i, 
	// 正确：当前目录的上级目录执行也OK
	var workerProcess = child_process.exec('node ' + __dirname + '/support.js ' + i, 
	function(err, stdout, stderr){
		if (err) {
			console.log(err.stack);
			console.log(err.code);
			console.log(err.signal);
		}
		
		console.log('stdout: ' + stdout);
		console.log('stderr: ' + stderr);
	});
	
	workerProcess.on('exit', function(code) {
		console.log('子进程已退出，退出码：' + code);
	});
}
